package com.mt.grand.singleton.enums;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;

/**
 * 通过一个单元素枚举实现单例
 */
public class EnumSingletonTest {

    public static void main(String[] args) throws IOException {
        int count = 100;
        final CountDownLatch countDownLatch = new CountDownLatch(count);

        for (int i = 0; i < count; i++) {
            new Thread(new Runnable() {
                public void run() {
                    try {
                        countDownLatch.await();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(EnumSingleton.SINGLE_INSTANCE.getInstance());
                }
            }).start();
            countDownLatch.countDown();
        }
        System.in.read();

    }
}